import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PunchItem {
    public enum Status {
        PUNCH_OUT, PUNCH_IN
    }
    private String name;    // 姓名
    private Long id;        // 员工号
    private Date punchIn;   // 上班打卡
    private Date punchOut;  // 下班打卡
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Date getPunchIn() {
        return punchIn;
    }
    public void setPunchIn(Date punchIn) {
        this.punchIn = punchIn;
    }
    public Date getPunchOut() {
        return punchOut;
    }
    public void setPunchOut(Date punchOut) {
        this.punchOut = punchOut;
    }
    public PunchItem(long id, String name) {
        this.id = id;
        this.name = name;
    }
    void punchByDate(Date d) {
        if (this.punchIn == null && this.punchOut == null) {
            // 打卡记录为空
            this.punchIn = d;
        } else if (this.punchIn != null && this.punchOut == null) {
            // 存在一条打卡记录->比较第一条记录
            if (this.punchIn.after(d)) {
                this.punchOut = this.punchIn;
                this.punchIn = d;
            } else {
                this.punchOut = d;
            }
        } else {
            // 存在两条打卡记录->比较两次打卡记录
            assert this.punchIn != null;
            if (this.punchIn.after(d)) {
                this.punchIn = d;
            } else if (this.punchOut.before(d)) {
                this.punchOut = d;
            }
        }
    }
    void punchByString(String s, SimpleDateFormat format) {
        Date d = null;
        try {
            d = format.parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
            return;
        }
        this.punchByDate(d);
    }
}
